#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int MAXN = 1e4 + 10;

int b[MAXN][10];
int n, m;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin >> n >> m;
    for (int i=1; i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>b[i][j];
    
    bool flag = true;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (i > 1) {
                if (b[i][j] - b[i-1][j] != 7) {
                    flag = false;
                    break;
                }
            }

            if (j > 1) {
                if (b[i][j] - b[i][j-1] != 1) {
                    flag = false;
                    break;
                }

                if (j != m && b[i][j] % 7 == 0) {
                    flag = false;
                    break;
                }
            }
        }
    }

    puts(flag ? "Yes" : "No");
    return 0;
}